<?php

namespace addons\csmitsm\library\xcore\xcflow\utils\xcformfields\xcform\base;

use addons\csmitsm\library\sdnode\xstack\utils\XsJsonUtils;
use addons\csmitsm\library\xcore\xcore\XcException; 


abstract class XcflowAField
{
    protected $xcfieldjsonObj = null;
    protected $fieldjsonobj = null; 
    public function __construct($xcfieldjsonObj)
    {
        $this->xcfieldjsonObj = $xcfieldjsonObj;
        // $this->fieldjsonobj = json_decode($xcfieldjsonObj['fieldjson'], true);
        $this->fieldjsonobj = XsJsonUtils::stringToJson($xcfieldjsonObj['fieldjson']);
    }

    public abstract function getDbfieldColumnType();

    public abstract function assertXcfieldjson();

    public abstract function pagevalueToDbvalue($pagevalue);

    public abstract function dbvalueToPagevalue($pagevalue);

    protected function assertRequired($configname){
        $json = $this->fieldjsonobj;
        $title = isset($json["xcform_base_xctitle"]["value"])?$json["xcform_base_xctitle"]["value"]:"";
        throw new XcException("字段配置不完整 : {$title} - {$configname}");
    }
}
